package cn.dubito.o2o.utils;

/**
 * @author liliang
 * @description:
 * @date 2018/4/18.
 */
public class PathUtil {

    /**
     * windows 系统前缀
     */
    private static final String WIN_PREFIX = "win";

    /**
     * 获取系统的分割符
     */
    private static final String SEPARATOR = System.getProperty("file.separator");

    /**
     * 获取图片存储绝对根路径
     *
     * @return
     */
    public static String getImageBasePath() {
        String os = System.getProperty("os.name");
        String basePath = "";
        if (os.toLowerCase().startsWith(WIN_PREFIX)) {
            basePath = "C:/project/image/";
        } else {
            basePath = "/Users/liliang/Downloads/apache-tomcat-8.5.15/webapps/image/";
        }
        // 替换系统分割符
        basePath = basePath.replace("/", SEPARATOR);
        return basePath;
    }

    /**
     * 获取图片存储相对路径
     *
     * @param id
     * @return
     */
    public static String getShopImagePath(long id) {
        String imagePath = "/upload/item/shop/" + id + "/";
        return imagePath.replace("/", SEPARATOR);
    }
}
